package com.ztc.mapper;
import com.ztc.beans.Book;
import com.ztc.beans.Jbook;
import com.ztc.service.BookService;
import com.ztc.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;

    @Override
    public void delBook(int id1) {
        bookMapper.delBook(id1);
    }

    @Override
    public Book getBookById(int id1) {
        if(id1>0){

           Book book = bookMapper.getBookById(id1);
           return book;
        }
        return null;
    }

    @Override
    public Book getBookById(String id) {
        if(id!=null&&!id.equals("")){
            int id1 = Integer.parseInt(id);
            return bookMapper.getBookById(id1);
        }
        return null;
    }

    @Override
    public void upBook(int i, Book book1) {
        bookMapper.upBook(i,book1);
    }

    @Override
    public void addBoook(Book book) {
        bookMapper.addBoook(book);
    }

    @Override
    public boolean getBookName(String name) {
        Book book =bookMapper.getBookName(name);
        if(book!=null&&!book.equals("")){
            return true;
        }
        return false;
    }

    @Override
    public Book getBookById1(Integer id1) {
        //拆箱
        int id = id1.intValue();
        return bookMapper.getBookById1(id);
    }

    @Override
    public void upbookBsum1(int i) {

    }

    @Override
    public void addjbook(int id, String bid) {

    }

    @Override
    public boolean getjbook(int id, String bid) {
        return false;
    }

    @Override
    public List<Jbook> getjbooks(int id) {
        return Collections.emptyList();
    }

    @Override
    public void upbookBsum2(String bid) {

    }

    @Override
    public void upjbook(String id) {

    }

    @Override
    public boolean getjbook(String bid) {
        return false;
    }

    @Override
    public int getBookSum(String bname, String author) {
        System.out.println(bookMapper.getBookSum(bname,author));
        return bookMapper.getBookSum(bname,author);
    }

    @Override
    public List<Book> getbooks(String bname, String author, Page page) {
        HashMap map = new HashMap();
        map.put("bname",bname);
        map.put("author",author);
        map.put("page",page);
        int offset = page.getPageSize() * (page.getCurrentPage() - 1);
        map.put("offset", offset);
        map.put("pageSize", page.getPageSize());
        List<Book> blist = bookMapper.getbooks(map);
        return blist;
    }
}
